<template>
    <el-container>
        <el-container class="is-vertical">
            <div class="title-box">
                <sc-title :title="mapTitle" style="margin-top: 15px;margin-left: 10px;border-bottom: 0px solid #eee;"></sc-title>
                <div class="title-box-right">
                    <el-button type="text" size="small" @click="table_show()">更多</el-button>
                </div>
            </div>
            <el-main class="nopadding">
                <scTable ref="table" :apiObj="$API.classHour.log.list" remoteSort :params="search" @selection-change="selectionChange" @dataChange="dataChange" :height="440">
                    <el-table-column label="序号" prop="index" width="70" align="left"></el-table-column>
                    <el-table-column label="来源" prop="originAgent" width="160" align="center">
                        <template #default="scope">
                            {{ scope.row.originAgent ? scope.row.originAgent.name : '' }}
                        </template>
                    </el-table-column>
                    <el-table-column label="机构名称" prop="agent" align="center" width="160">
                        <template #default="scope">
                            {{ scope.row.agent ? scope.row.agent.name : '' }}
                        </template>
                    </el-table-column>
                    <el-table-column label="学员姓名" prop="user" width="150" align="center">
                        <template #default="scope">
                            {{ scope.row.user ? scope.row.user.name : '' }}
                        </template>
                    </el-table-column>
                    <el-table-column label="类型" prop="type" width="160" align="center">
                        <template #default="scope">
                            {{ scope.row.type ? scope.row.type.name : '' }}
                        </template>
                    </el-table-column>
                    <el-table-column label="课时类型" prop="classHourType" width="120" align="center">
                        <template #default="scope">
                             {{ scope.row.classHourType ? scope.row.classHourType.name : '' }}
                        </template>
                    </el-table-column>
                    <el-table-column label="数量" prop="classHour" width="120" align="center">
                        <template #default="scope">
                            <template v-if="in_array(scope.row.type.value, [1,4,7,10,11])">
                                <div style="color: green;">+ {{ scope.row.classHour }}</div>
                            </template>
                            <template v-else>
                                <div style="color: red;">- {{ scope.row.classHour }}</div>
                            </template>
                        </template>
                    </el-table-column>
                    <el-table-column label="变更前数量" prop="beforeNumber" width="120" align="center">
                    </el-table-column>
                    <el-table-column label="变更后数量" prop="afterNumber" width="120" align="center">
                    </el-table-column>
                    <el-table-column label="金额" prop="amount" width="120" align="center">
                    </el-table-column>
                    <el-table-column label="付款方式" prop="paymentMethod" width="120" align="center">
                        <template #default="scope">
                             {{ scope.row.paymentMethod ? scope.row.paymentMethod.name : '0' }}
                        </template>
                    </el-table-column>
                    <el-table-column label="描述" prop="description" align="center" width="150" show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column label="操作者" prop="operator" width="160" align="center">
                        <template #default="scope">
                             {{ scope.row.operator ? scope.row.operator.name : '' }}
                        </template>
                    </el-table-column>
                    <el-table-column label="创建时间" prop="createdAt" width="150" align="center"></el-table-column>
                </scTable>
            </el-main>
        </el-container>
    </el-container>


</template>

<script>
import { in_array } from '@/utils/index.js'
export default {
    components: {
    },
    props: {
        type: { type: Number, required: true, default: 0 },
        mapTitle: { type: String, required: true, default: ''}
	},
    data() {
        return {
            in_array,
            selection: [],
            search: {
                name: null,
            }
        }
    },
    mounted() {
       if (this.type) {
            this.search.type = this.type
       }
    },
    methods: {
        dataChange(res, tableData) {
			let total = res.data.total
            let perPage = res.data.perPage
            let page = (this.$refs.table && this.$refs.table.currentPage) || 1
            tableData.forEach((item, index) => {
				item.index = page * perPage + index - perPage + 1
            })
        },
        // 搜索
        upsearch() {
            this.$refs.table.upData(this.search)
        },
        //查看
        table_show() {
            this.$router.push({path: '/record/recharge'})
        },
        //表格选择后回调事件
        selectionChange(selection) {
            this.selection = selection;
        },
        //本地更新数据
        handleSuccess() {
            this.$refs.table.refresh()
        }
    }
}
</script>

<style scoped>

.title-box {
    display: flex;
    justify-content: space-between;
}

.title-box-right {
    margin-top: 8px;
    margin-right: 10px;
}

:deep(.el-button--text span) {
    font-size: 17px;
    font-weight: bold;
}

</style>
